﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;

namespace ServerMonitor
{
    public class SnmpListSection : ConfigurationSection
    {
        public override bool IsReadOnly()
        {
            return true;
        }

        [ConfigurationProperty("snmpList", IsDefaultCollection = false)]
        [ConfigurationCollection(typeof(SnmpSection), CollectionType = ConfigurationElementCollectionType.AddRemoveClearMap, RemoveItemName = "remove")]
        public SnmpSectionContainer SnmpSectionContainer
        {
            get
            {
                return (SnmpSectionContainer)base["snmpList"];
            }
        }
    }

    public class SnmpSectionContainer : ConfigurationElementCollection
    {
        protected override ConfigurationElement CreateNewElement()
        {
            return new SnmpSection();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((SnmpSection)element).DeviceName;
        }

        public SnmpSection this[int i]
        {
            get
            {
                return (SnmpSection)base.BaseGet(i);
            }
        }

        public SnmpSection this[string key]
        {
            get
            {
                return (SnmpSection)base.BaseGet(key);
            }
        }
    }

    public class SnmpSection : ConfigurationElement
    {
        public override bool IsReadOnly()
        {
            return true;
        }

        [ConfigurationProperty("deviceName", IsRequired = true)]
        public string DeviceName
        {
            get { return this["deviceName"] as string; }
        }

        [ConfigurationProperty("portCount", IsRequired = true, DefaultValue = 24)]
        public int PortCount
        {
            get { return (int)this["portCount"]; }
        }

        [ConfigurationProperty("ipAddress", IsRequired = true)]
        public string IpAddress
        {
            get { return this["ipAddress"] as string; }
        }


        [ConfigurationProperty("usedMemoryCommand", IsRequired = true)]
        public string UsedMemoryCommand
        {
            get { return this["usedMemoryCommand"] as string; }
        }

        [ConfigurationProperty("freeMemoryCommand", IsRequired = true)]
        public string FreeMemoryCommand
        {
            get { return this["freeMemoryCommand"] as string; }
        }

        [ConfigurationProperty("cpuLoadCommand", IsRequired = true)]
        public string CpuLoadCommand
        {
            get { return this["cpuLoadCommand"] as string; }
        }

        [ConfigurationProperty("temperatureCommand", IsRequired = true)]
        public string TemperatureCommand
        {
            get { return this["temperatureCommand"] as string; }
        }

        [ConfigurationProperty("trapString", IsRequired = false, DefaultValue = "public")]
        public string TrapString
        {
            get { return this["trapString"] as string; }
        }

        //[ConfigurationProperty("userName", IsRequired = true, DefaultValue = "administrator")]
        ////[IntegerValidator(MaxValue = 65535, MinValue = 1)]
        //public string UserName
        //{
        //    get { return this["userName"] as string; ; }
        //}
    }
}
